package com.xdf.ecommerce.stream.customChannel;

import com.alibaba.fastjson.JSON;
import com.xdf.ecommerce.vo.SCSMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.Payload;

/**
 * 使用自定义信道实现接受消息
 * @author chanchaw
 * @create 2025-11-06 15:57
 */
@Slf4j
@RequiredArgsConstructor
@EnableBinding(MySink.class)
public class MyReceiveService {
    /** 使用自定义的信道接受消息 **/
    @StreamListener(MySink.INPUT)
    public void receiveMessage(@Payload Object payload){
        SCSMessage scsMessage = JSON.parseObject(payload.toString(), SCSMessage.class);
        log.info("使用自定义信道接受到的消息是：[{}]", scsMessage.toString());
    }
}
